#include "DonThuc.h"
#include <string>
#include <math.h>
#include <sstream>
DonThuc::DonThuc()
{
	this->k=1;
	this->m_heSo=0;
	this->m_soMu=0;
}
DonThuc::DonThuc(float a,float b)
{
	this->m_heSo=a;
	this->m_soMu=b;
}
DonThuc::~DonThuc()
{
}
BieuThuc& DonThuc::khoitao(float *x,int i)
{
	this->k=x[i];
	i++;
	this->m_heSo=x[i];
	i++;
	this->m_soMu=x[i];
	i++;
	return *this;
}
string DonThuc::bieuDien()
{
	stringstream ss (stringstream::in | stringstream::out);
	ss << m_heSo;
	if(m_soMu ==1 )
	{
		ss<<"x^";
		ss<<m_soMu;
	}
	else 
	{
		ss<<"x";
	}
	
	return ss.str();
}

string DonThuc::bieuDienDaoHam()
{
	stringstream ss (stringstream::in | stringstream::out);
	ss << m_heSo * m_soMu;
	ss<<"x^";
	ss<< this->m_soMu -1;
	return ss.str();
}

float DonThuc::tinhDaoHam(float x)
{
	return pow(this->m_heSo * this->m_soMu * x, this->m_soMu-1);
}

float DonThuc::tinhGiaTri(float x)
{
	return pow(this->m_heSo*x,this->m_soMu);
}